package com.crm.customers.dao.impl;

import java.util.List;

import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Repository;

import com.crm.base.dao.BaseDao;
import com.crm.customers.dao.CustomerDao;
import com.crm.customers.model.CustomerInfo;

@Repository("customerDao")
public class CustomerDaoImpl extends BaseDao implements CustomerDao {
	
	private  static final String MAPPER_NAMESAPCE = "CustomerMapper.";

	@Override
	public int getCustomerInfoVerifyCount(CustomerInfo info) {
		return selectOne(MAPPER_NAMESAPCE+"getCustomerInfoVerifyCount", info);
	}

	@Override
	public CustomerInfo insertCustomerInfo(CustomerInfo cinfo) {
		insert(MAPPER_NAMESAPCE+"insertCustomerInfo", cinfo);
		return cinfo;
	}

	@Override
	public CustomerInfo updateCustomerInfo(CustomerInfo cinfo) {
		update(MAPPER_NAMESAPCE+"updateCustomerInfo", cinfo);
		return cinfo;
	}

	@Override
	public List<CustomerInfo> getCustomerInfoList(CustomerInfo cinfo) {
		List<CustomerInfo> list = selectList(MAPPER_NAMESAPCE+"getCustomerInfoList", cinfo);
		if (list != null && list.size() > 0) {
			for(CustomerInfo c:list) {
				c.setCreateuserName((String)selectOne(MAPPER_NAMESAPCE+"getcname", c.getUid()));
				c.setDystate((Integer)selectOne(MAPPER_NAMESAPCE+"getcstate", c.getId()));   
			}
			
			list.get(0).setTotalResults((Integer)selectOne(MAPPER_NAMESAPCE+"getCustomerInfoListCount", cinfo));
		}
		return list;
	}

	@Override
	public CustomerInfo getCustomerInfoById(Long id) {
		return selectOne(MAPPER_NAMESAPCE+"getCustomerInfoById", id);
	}

 

	@Override
	public List<CustomerInfo> getCustomerByKeyWord(CustomerInfo cinfo) {
		List<CustomerInfo> list = selectList(MAPPER_NAMESAPCE+"getCustomerByParam", cinfo);
		if (list != null && list.size() > 0) {
			list.get(0).setTotalResults((Integer)selectOne(MAPPER_NAMESAPCE+"getCustomerByParamCount", cinfo));
		}
		return list;
	}

 

	@Override
	public int getCustomerTypeinCount(CustomerInfo cinfo) {
		return selectOne(MAPPER_NAMESAPCE+"getCustomerInfoById", cinfo);
	}

	@Override
	public int updateCustomerFirm(CustomerInfo cinfo) {
		return 0;
	}

	@Override
	public String getCallingCodeById(Long contentid) {
		return null;
	}

	@Override
	public int updateCustomerCreateUser(CustomerInfo cinfo) {
		return 0;
	}

	@Override
	public int updateByPrimaryKeySelective(CustomerInfo cinfo) {
		return 0;
	}

	@Override
	public List<CustomerInfo> getCustomerInfoAllList(CustomerInfo cinfo) {
		List<CustomerInfo> list = selectList(MAPPER_NAMESAPCE+"customerInfoAllList", cinfo);
		return list;
	}

	@Override
	public int updateCustomerState(CustomerInfo cinfo) {
		return update(MAPPER_NAMESAPCE+"updateCustomerState", cinfo);
	}

	@Override
	public int updateCustomerName(CustomerInfo cinfo) {
		return update(MAPPER_NAMESAPCE+"updateCustomerName", cinfo);
	}

	@Override
	public List<CustomerInfo> getBookingCustomerInfoList(CustomerInfo cinfo) {
		List<CustomerInfo> list = selectList(MAPPER_NAMESAPCE+"getBookingCustomerInfoList", cinfo);
		if (list != null && list.size() > 0) {
			list.get(0).setTotalResults((Integer)selectOne(MAPPER_NAMESAPCE+"getBookingCustomerInfoListCount", cinfo));
		}
		return list;
	}

	@Override
	public List<CustomerInfo> getLXCustomerInfoList(CustomerInfo cinfo) {
		List<CustomerInfo> list = selectList(MAPPER_NAMESAPCE+"getLXCustomerInfoList", cinfo);
		if (list != null && list.size() > 0) {
			list.get(0).setTotalResults((Integer)selectOne(MAPPER_NAMESAPCE+"getLXCustomerInfoListCount", cinfo));
		}
		return list;
	}

	@Override
	public int updateCustomerCategory(CustomerInfo cinfo) {
		return update(MAPPER_NAMESAPCE+"updateCustomerCategory", cinfo);
	}

	@Override
	public List<CustomerInfo> transformlist(CustomerInfo cinfo) {
		List<CustomerInfo> list = selectList(MAPPER_NAMESAPCE+"transformlist", cinfo);
		if (list != null && list.size() > 0) {
			list.get(0).setTotalResults((Integer)selectOne(MAPPER_NAMESAPCE+"transformlistcount", cinfo));
		}
		return list;
	}

	@Override
	public int transCustomerAll(CustomerInfo cinfo) {
		return update(MAPPER_NAMESAPCE+"transCustomerAll", cinfo);
	}

	@Override
	public int getCustomerInfoTotalSizeByParams(CustomerInfo info) {
		return selectOne(MAPPER_NAMESAPCE+"transformlistcount", info);
	}

	@Override
	public List<CustomerInfo> getAllRemindCustomer() {
		return selectList(MAPPER_NAMESAPCE+"getAllRemindCustomer");
	}

	@Override
	public List<CustomerInfo> getContractCustomerList(CustomerInfo info) {
		List<CustomerInfo> list = selectList(MAPPER_NAMESAPCE+"getContractCustomerList", info);
		if (list != null && list.size() > 0) {
			list.get(0).setTotalResults((int)selectOne(MAPPER_NAMESAPCE+"getContractCustomerListCount", info));
		}
		return list;
	}

	@Override
	public List<CustomerInfo> getQualificationCustomerList(CustomerInfo info) {
		List<CustomerInfo> list = selectList(MAPPER_NAMESAPCE+"getQualificationCustomerList", info);
		if (list != null && list.size() > 0) {
			list.get(0).setTotalResults((int)selectOne(MAPPER_NAMESAPCE+"getQualificationCustomerListCount", info));
		}
		return list;
	}
	
	@Override
	public int getResourceCount(CustomerInfo info) {
		return selectOne(MAPPER_NAMESAPCE+"getResourceCount", info);
	}

	@Override
	public List<CustomerInfo> getAllDiscardCustomer() {
		return selectList(MAPPER_NAMESAPCE+"getAllDiscardCustomer");
	}

	@Override
	public int updateAllDiscardCustomer() {
		return update(MAPPER_NAMESAPCE+"updateAllDiscardCustomer");
	}

	@Override
	public List<CustomerInfo> getAllwaitForAnchoredList(CustomerInfo ci) {
		List<CustomerInfo> list = selectList(MAPPER_NAMESAPCE+"getAllwaitForAnchoredList", ci);
		if (list != null && list.size() > 0) {
			list.get(0).setTotalResults((int)selectOne(MAPPER_NAMESAPCE+"getAllwaitForAnchoredCount", ci));
		}
		return list;
	}

	@Override
	public List<CustomerInfo> getCusListByTel(CustomerInfo ci) {
		return selectList(MAPPER_NAMESAPCE+"getCusListByTel", ci);
	}

	@Override
	public List<CustomerInfo> getCustomerServiceListByParams(CustomerInfo ci) {
		
		List<CustomerInfo> list = selectList(MAPPER_NAMESAPCE+"getCustomerServiceListByParams", ci);
		if (list != null && list.size() > 0) {
			list.get(0).setTotalResults((Integer)selectOne(MAPPER_NAMESAPCE+"getCustomerServiceListCountByParams", ci));
		}
		return list;
	}
	
	@Override
	public int getAllwaitForAnchoredMoney(CustomerInfo info) {
		return selectOne(MAPPER_NAMESAPCE+"getAllwaitForAnchoredMoney", info);
	}

	@Override
	public List<CustomerInfo> getCustomerQualificationInfoList(CustomerInfo cinfo) {
		List<CustomerInfo> list = selectList(MAPPER_NAMESAPCE+"getCustomerQualificationInfoList", cinfo);
		if (list != null && list.size() > 0) {
			list.get(0).setTotalResults((Integer)selectOne(MAPPER_NAMESAPCE+"getCustomerQualificationInfoCount", cinfo));
		}
		return list;
	}

	@Override
	public List<CustomerInfo> getCustomerQualificationUserList(CustomerInfo cinfo) {
		List<CustomerInfo> list = selectList(MAPPER_NAMESAPCE+"getCustomerQualificationUserList", cinfo);
		if (list != null && list.size() > 0) {
			list.get(0).setTotalResults((Integer)selectOne(MAPPER_NAMESAPCE+"getCustomerQualificationUserListCount", cinfo));
		}
		return list;
		
		
	}

	@Override
	public int getIdCardCount(CustomerInfo info) {
		return selectOne(MAPPER_NAMESAPCE+"getIdCardCount", info);
	}

	public List<CustomerInfo> getQualificationUserList(CustomerInfo cinfo) {
		return selectList(MAPPER_NAMESAPCE+"getQualificationUserList", cinfo);
	}

	@Override
	public CustomerInfo getQualificationCustomerInfo(CustomerInfo cinfo) {
		return selectOne(MAPPER_NAMESAPCE+"getQualificationCustomerInfo", cinfo);
	}

	@Override
	public List<CustomerInfo> getGaokaoCustomerList(CustomerInfo info) {
		List<CustomerInfo> list = selectList(MAPPER_NAMESAPCE+"getGaokaoCustomerList", info);
		if (list != null && list.size() > 0) {
			list.get(0).setTotalResults((int)selectOne(MAPPER_NAMESAPCE+"getGaokaoCustomerListCount", info));
		}
		return list;
	}

	@Override
	public List<CustomerInfo> getCustomerByBiz(CustomerInfo info) {
		List<CustomerInfo> list = selectList(MAPPER_NAMESAPCE+"getCustomerByBiz", info);
		if (list != null && list.size() > 0) {
			list.get(0).setTotalResults((Integer)selectOne(MAPPER_NAMESAPCE+"getCustomerByBizCount", info));
		}
		return list;
	}

	@Override
	public int getQualificationCustomerSize(Long customerId) {
		// TODO Auto-generated method stub
		return selectOne(MAPPER_NAMESAPCE+"getQualificationCustomerSize", customerId);
	}
}
